#!/bin/sh
# postinst framework for openpanel packages
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
    configure)
grep "^lima" /etc/postfix/master.cf >/dev/null 2>&1 || {
  cat >> /etc/postfix/master.cf << _EOF_
lima    unix    -       n       n       -       -       pipe
  flags=F user=lima argv=/usr/local/bin/lima-submit $recipient $sender
_EOF_
}
ln -sf /var/lima/bin/limadaemon.app/exec /var/lima/bin/limadaemon
ln -sf /var/limb/bin/limasubmit.app/exec /var/lima/bin/limasubmit
groupadd -f lima > /dev/null
if grep -q "lima" /etc/passwd; then
        echo "User already created"
else
        echo "Creating opencore user"
        useradd lima -r -g lima > /dev/null
fi
update-rc.d limadaemon start 94 2 3 4 5 . stop 74 0 1 6 . > /dev/null
chown lima:lima /var/lima/lists
chown -R lima:lima /var/lima/queue
chown -R lima:lima /var/lima/templates

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


